/*
 *
调用C库中的qsort函数来实现整形数组的排序
qsort函数需要传入自定义函数的函数指针

1 23 23 46 56 
a b d h i 
1.000000 2.300000 2.300000 4.600000 5.600000 

 */
#include<stdio.h>
#include<stdlib.h>

int compare_fun(const void *p1, const void *p2){
	return *((int *)p1) - *((int *)p2);
}
int compare_fun1(const void *p1, const void *p2){
	return *((char *)p1) - *((char *)p2);
}
int compare_fun2(const void *p1, const void *p2){
	return *((double *)p1) - *((double *)p2) > 0 ? 1 : -1;
}

int main(){
	int _int[] = {56,23,1,46,23};
	char _char[] = {'a','h','b','d','i'};
	double _double[] = {5.6,2.3,1,4.6,2.3};

	qsort(_int, sizeof(_int)/sizeof(int), sizeof(int), compare_fun);
	qsort(_char, sizeof(_char)/sizeof(char), sizeof(char), compare_fun1);
	qsort(_double, sizeof(_double)/sizeof(double), sizeof(double), compare_fun2);

	for(int i = 0; i < 5; i++ ){
		printf("%d ",_int[i]);
	}
	printf("\n");
	for(int i = 0; i < 5; i++ ){
		printf("%c ",_char[i]);
	}
	printf("\n");
	for(int i = 0; i < 5; i++ ){
		printf("%lf ",_double[i]);
	}
	printf("\n");
}
